#!/usr/bin/perl
# scope-our.pl
use warnings;
use strict;

package MyPackage;

my $my_var = "my-var";   # file-global lexical variable
our $our_var = "our-var";   # global to be localized with 'our'
our $local_var = "global-var";   # global to be localized with 'local'
use vars qw($use_var);   # define 'MyPackage::use_var' which exists 
                         # only in this package
$use_var = "use-var";

### ERROR: the global variable is not declared
# $package_variable = "eek";

package AnotherPackage;

print "Outside, my_var is '$my_var' \n";   # display 'my-var'
print "Outside, our_var is '$our_var' \n";   # display 'our-var'
print "Outside, local_var is '$local_var' \n";   # display 'global-var'

### ERROR: $use_var doesn't exist in this package 
# print "Outside, use_var is '$use_var' \n"; 

sub mysub {
   my $my_var = "my_in_mysub";
   our $our_var = "our_in_mysub";
   local $local_var = "local_in_mysub";

   ### ERROR: global $use_var does not exist in this package
   # local $use_var = "local_use_in_mysub";

   print "In mysub, my_var is '$my_var'\n";   # display 'my_in_mysub'
   print "In mysub, our_var is '$our_var'\n";   # display 'our_in_mysub'
   print "In mysub, local_var is '$local_var'\n"; # display 'local_in_mysub'
   mysub2();
}
 
sub mysub2 {
   print "In mysub2, my_var is '$my_var' \n";   # display 'my-var'
   print "In mysub2, our_var is '$our_var' \n";   # display 'our-var'
   print "In mysub2, local_var is '$local_var' \n";   # display 'local_in_mysub'
}

mysub;

print "Again outside, my_var is '$my_var' \n";   # display 'my-var'
print "Again outside, our_var is '$our_var' \n";   # display 'our-var'
print "Again outside, local_var is '$local_var' \n"; # display 'global-var'